__doc__ =   """ Misc. general functions not related to structural bioinformatics.
            """
#comment: ready for 0.9

from cPickle import dumps, loads
from gzip import GzipFile

def deep_list(x):
    """ tuple recursivly to list
    """
    if isinstance(x, tuple):
        return map(deep_list, x)
    return x

def deep_tuple(x):
    """ list recursivly to tuple
    """
    if isinstance(x, list):
        return tuple(map(deep_tuple, x))
    return x

def between((min_, max_), number):
    """ Same as: min_ <= number <= max_
    """
    return min_ <= number <= max_

def combinate(items, n):
    """ returns combinations of items.
    """
    if n==0: yield []
    else:
        for i in xrange(len(items)- n + 1):
            for cc in combinate(items[i + 1:],n - 1):
                yield [items[i]] + cc

def gzip_dump(object, filename, bin =2):
    """ Saves a compressed object to disk
    """
    file = GzipFile(filename, 'wb')
    file.write(dumps(object, bin))
    try: # do not leave unlinked structures
        object.link()
    except AttributeError:
        pass
    file.close()

def gzip_load(filename):
	"""Loads a compressed object from disk
	"""
	file = GzipFile(filename, 'rb')
	buffer = ""
	while 1:
		data = file.read()
		if data == "":
			break
		buffer += data
	object = loads(buffer)
	file.close()
	return object

#END